package algorithm.tree;

import algorithm.model.TreeNode;

/**
 * https://leetcode.com/problems/invert-binary-tree/
 * Easy
 * 翻转二叉树
 * Created by yzy on 2021-03-18 16:41
 */
public class InvertbinaryTree {

    /**
     * Time 0ms, 100%
     * Memory 36MB, 95.58%
     * @param root
     * @return
     */
    public TreeNode invertTree(TreeNode root) {
        if(root==null) return null;
        invertTree(root.left);
        invertTree(root.right);
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        return root;
    }
}
